package com.mashuai.utils.ztest.toolkit.tree;

import com.mashuai.utils.toolkit.core.msConverts.MsTreeUtils;
import com.mashuai.utils.toolkit.core.msMp.MsDb;
import com.mashuai.utils.ztest.pb.bean.MsDept;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

/**
 * @ClassName: MpController
 * @Description:
 */
@RestController
@RequestMapping("/tree")
public class TreeController {

    public List<TreeNode> getData() {
        List<MsDept> list = MsDb.list(null, MsDept.class);
        List<TreeNode> treeNodeList = new ArrayList<TreeNode>();
        for (MsDept t : list) {
            treeNodeList.add(new TreeNode(t.getId(), t.getParentId(), t.getDepName()));
        }
        return treeNodeList;

    }

    @GetMapping("/createTree")
    public Object createTree() {
        List<TreeNode> data = getData();
        //MsTreeUtils.buildTreeStructure(data, TreeNode::getId, TreeNode::getPid, TreeNode::setTreeNodes, 0);
        //List<TreeNode> allChildNodes = MsTreeUtils.getAllChildNodes(data, TreeNode::getId, TreeNode::getPid, 12, true);
        List<TreeNode> nodePath = MsTreeUtils.getNodePath(data, TreeNode::getId, TreeNode::getPid, 11, 0);
        return nodePath;
    }


}
